package com.zhangxu.microservice.auth.dao.condition;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zhangxu.microservice.common.utils.AssertUtils;
import lombok.Data;

@Data
public class PageCondition {

    /**
     * 当前页码
     */
    private Integer pageNum;

    /**
     * 每页条数
     */
    private Integer pageSize;

    /**
     * 是否进行count查询
     */
    private Boolean searchCount = true;

    public void checkPage() {
        AssertUtils.notNull(pageNum, "pageNum不能为空");
        AssertUtils.notNull(pageSize, "pageSize不能为空");
    }

    /**
     * 获取mybatisPlus的page对象
     *
     * @return {@link IPage}<{@link T}>
     */
    public <T> IPage<T> getIpage() {
        return new Page<>(this.getPageNum(), this.getPageSize(), this.getSearchCount());
    }
}